package com.example.peibei.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dingtao.common.bean.BillRecord;
import com.example.peibei.R;
import com.example.peibei.ui.activity.BillRecordActivity;

import java.util.ArrayList;
import java.util.List;

public class BillRecordAdapter extends BaseQuickAdapter<BillRecord.RecordsDTO, BaseViewHolder> {
    Context context;
    List<BillRecord.RecordsDTO.ItemDTO> list;

    public BillRecordAdapter(@Nullable List<BillRecord.RecordsDTO> data, Context context) {
        super(R.layout.item_bill_record, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, BillRecord.RecordsDTO item) {
        list = new ArrayList<>();
        helper.setText(R.id.tv_time, item.getDate());
        RecyclerView rv_bill_detail = helper.getView(R.id.rv_bill_detail);
        rv_bill_detail.setLayoutManager(new LinearLayoutManager(context));
        BillRecordDetailAdapter billRecordDetailAdapter = new BillRecordDetailAdapter(list, context);
        rv_bill_detail.setAdapter(billRecordDetailAdapter);
        list.addAll(item.getItem());
        billRecordDetailAdapter.notifyDataSetChanged();
        billRecordDetailAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                if (listener!=null){
                    listener.onClick(position,item.getItem().get(position).getId() + "");
                }
            }
        });
    }

    //第一步 定义接口
    public interface OnDetailClickListener {
        void onClick(int position,String logId);
    }

    private OnDetailClickListener listener;

    //第二步， 写一个公共的方法
    public void setOnDetailClickListener(OnDetailClickListener listener) {
        this.listener = listener;
    }
}
